<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('产品基本信息列表')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>商家名称：</label>
                            <select class="form-control" name="storeId">
                                <option value="">所有</option>
                                <option th:each="item:${storeInfoList}" th:value="${item.storeId}"
                                        th:text="${item.storeName}"></option>
                            </select>
                        </li>
                        <li>
                            <label>产品名称：</label>
                            <input type="text" name="prodName"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="prod:baseInfo:add">
                <i class="fa fa-plus"></i> 添加
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('prod:baseInfo:edit')}]];
    var removeFlag = [[${@permission.hasPermi('prod:baseInfo:remove')}]];
    var prefix = ctx + "prod/baseInfo";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "产品基本信息",
            columns: [
                //     {
                //     checkbox: true
                // },
                // {
                //     field: 'id',
                //     title: '',
                //     visible: false
                // },
                {
                    field: 'prodName',
                    title: '产品名称',
                    formatter: function (value, row, index) {
                        return row.prodName + ' [' + row.id + ']'
                    }
                },
                {
                    field: 'prodLogo',
                    title: '产品logo',
                    formatter: function (value, row, index) {
                        return $.table.imageView(row.prodLogo, 500, 500)
                    }
                },
                // {
                //     field: 'storeId',
                //     title: '商家ID'
                // },
                {
                    field: 'storeName',
                    title: '商家名称',
                    formatter: function (value, row, index) {
                        return row.storeName + ' [' + row.storeId + ']'
                    }
                },

                {
                    field: 'termInfo',
                    title: '租机期限'
                },
                {
                    field: 'labelInfo',
                    title: '标签信息'
                },
                {
                    field: 'applyNumber',
                    title: '申请人数'
                },
                {
                    title: '产品详情',
                    formatter: function (value, row) {
                        if (row.prodUrl) {
                            return '<a href="' + row.prodUrl + '" target="_blank">预览</a>';
                        } else {
                            return '暂无';
                        }
                    }
                },
                // {
                //     field: 'status',
                //     title: '状态',
                //     formatter: function (value, row) {
                //         return statusTools(row);
                //     }
                // },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /* 用户状态显示 */
    function statusTools(row) {
        if (row.status == 0) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
        }
    }

    /* 用户管理-停用 */
    function disable(id) {
        $.modal.confirm("确认要停用吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id, "status": 0});
        })
    }

    /* 用户管理启用 */
    function enable(id) {
        $.modal.confirm("确认要启用吗？", function () {
            $.operate.post(prefix + "/changeStatus", {"id": id, "status": 1});
        })
    }
</script>
</body>
</html>